package com.weike.wk_android.widget.dialog;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.weike.wk_android.R;
import com.weike.wk_android.impl.NormalDialogListener;

import androidx.annotation.NonNull;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 提示对话框
 */
public class NormalDialog extends Dialog {
    @BindView(R.id.title)
    TextView title;
    @BindView(R.id.msg)
    TextView msg;

    @BindView(R.id.closed)
    ImageView closed;
    @BindView(R.id.cancel)
    Button cancel;
    @BindView(R.id.ok)
    Button ok;

    private NormalDialogListener dialogListener;

    private String titleStr;
    private String msgStr;
    private String okStr;
    private String cancelStr;

    public NormalDialog(@NonNull Context context,
                        NormalDialogListener dialogListener,
                        String title,
                        String msg,
                        String okString,
                        String cancelString
    ) {
        super(context);
        this.dialogListener = dialogListener;

        titleStr = title;
        msgStr = msg;
        okStr = okString;
        cancelStr = cancelString;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dialog_normal);
        ButterKnife.bind(this);

        initData();
    }

    /**
     * 初始化数据信息
     */
    private void initData() {
        if (!TextUtils.isEmpty(titleStr)) {
            title.setText(titleStr);
        }

        if (!TextUtils.isEmpty(msgStr)) {
            msg.setText(msgStr);
        }

        if (!TextUtils.isEmpty(okStr)) {
            ok.setText(okStr);
        }

        if (!TextUtils.isEmpty(cancelStr)) {
            cancel.setText(cancelStr);
        }
    }

    @OnClick({R.id.closed, R.id.cancel, R.id.ok})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.closed:
                cancel();
                break;
            case R.id.cancel:
                dialogListener.cancel();
                cancel();
                break;
            case R.id.ok:
                dialogListener.ok();
                cancel();
                break;
        }
    }
}
